<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="java.net.URLEncoder" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<% String basePath = request.getContextPath();
   String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+basePath;
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<style type="text/css">
*{margin:0; padding:0; border:0; list-style:none}
.box{width:850px; height:428px;  background:#FFF; border:1px solid #adadad; margin:0 auto;}
.left{width:437px; padding-top:50px; padding-left:33px; padding-right:43px; margin:auto}
.right{ width:295px; padding-left:40px; float:left; padding-top:50px;}
.boxline{width:438px; height:27px; margin-bottom:30px;}
.btn{width:88px; height:27px; background:url(<%=basePath%>/jsps/images/web_03.jpg) no-repeat left top; text-align:center; font-family:"宋体"; font-size:12px; line-height:27px; color:#FFF;}
.btn:hover{background:url(<%=basePath%>/jsps/images/ss.jpg) no-repeat;}
.textline{width:79px; height:18px; border:#8798a0 1px solid; padding-left:5px; line-height:18px; font-family:"宋体"; font-size:12px; color:#616161;}
.textmain{width:206px; height:203px; border:2px solid #999999; padding:20px 12px; overflow:hidden }
</style>
<script type="text/javascript" src="<%=basePath%>/prototype.js"></script>
<head>
    <title></title>
</head>
<body>
<div class="box">
<div class="left">
	<div class="boxline">
    	<div style="width:88px; height:27px; float:left;"><input name="" type="button" class="btn" value="同步宝贝" onClick="javascrip:importProductData()"/></div>
        <div style="width:35px; height:27px; float:left;"></div>
        <div id="product" style="width:315px; height:27px; float:left;"><img src="<%=basePath%>/jsps/images/linknone.jpg" /></div>
        <div style=" clear:both; font-size:0px;"></div>
    </div>
    <div class="boxline">
    	<div style="width:88px; height:27px; float:left;"><input name="" type="button" class="btn" value="同步订单" onClick="javascrip:importOrderData()"/></div>
        <div style="width:35px; height:27px; float:left;"></div>
        <div id="order" style="width:315px; height:27px; float:left;"><img src="<%=basePath%>/jsps/images/linknone.jpg" /></div>
        <div style=" clear:both; font-size:0px;"></div>
    </div>
    <div style="width:100px; height:35px;"></div>
    
    <p style="width:428px; line-height:25px; font-family:'宋体'; font-size:12px; color:#616161;">
    <strong style="font-size:14PX; color:#5f5f5f;">使用说明：</strong><br />
      点击按钮，手动同步商品明细和订单。
      <br />
      同步商品：将淘宝店铺商品明细同步至百会CRM系统“我的宝贝”模块中。 
      <br />
      同步订单：将淘宝订单信息同步至百会CRM系统“订单”模块中，包括订单主题、买家名称、买家留言等。 
      <br />
      查看同步日志：选择同步时间段，点击“同步日志”按钮，在按钮下方的显示框内将呈现同步记录明细，包括同步操作者、同步时间和同步内容。
    </p>

</div>
<!-- 
<div class="right">
	<table width="240" height="335" border="0" cellpadding="0" cellspacing="0">
    	<TR valign="top">
        	<TD height="25" width="86"><strong style="color:#5f5f5f; font-size:12px">开始日期：</strong></TD>
            <TD height="25" width="30"></TD>
            <TD height="25" width="8"></TD>
            <TD height="25" width="86"><strong style="color:#5f5f5f; font-size:12px">结束日期：</strong></TD>
            <TD height="25" width="30"></TD>
        </TR>
        <TR valign="middle">
        	<TD height="20" width="86">
            <input name="" type="text" class="textline"  />
          </TD>
            <TD height="20" width="30" align="center"><img src="<%=basePath%>/jsps/images/web_08.jpg" style="cursor:pointer" /></TD>
            <TD height="20" width="8"><img src="<%=basePath%>/jsps/images/web_13.jpg" /></TD>
            <TD height="20" width="86">
            <input name="" type="text" class="textline"  />
          </TD>
            <TD height="20" width="30" align="center"><img src="<%=basePath%>/jsps/images/web_08.jpg" style="cursor:pointer" /></TD>
        </TR>
        <tr valign="top">
        	<td colspan="5" height="10"></td>
        </tr>
        <tr valign="top">
        	<td colspan="5" height="45">
            	<input name="" type="button" class="btn" value="同步日志"/>
            </td>
        </tr>
         <tr valign="top">
        	<td colspan="5" height="245">
  
            <textarea name="" cols="" rows="" class="textmain"></textarea>
            
            </td>
        </tr>
    </table>
</div>
 -->
</div>
<div style="clear:both;"></div>
<script>
	var timerProduct = null;
	var timerOrder = null;
	
	function importProductData(){
		ProgressBar.setProgress(1,0);
		var url = '<%=basePath%>/app?ACTION=importProductData&USERID=${baihuiId}&SIGN=${sign}&async=true';
		new Ajax.Request(url,{
			onComplete : callback1
		});
	}
	
	function callback1(response){
		var resText = response.responseText;
		if(resText != null && resText != ""){
			resText = resText.evalJSON();
		}
		var errMsg = resText.errMsg;
		if(errMsg != null){
			alert(errMsg);
			return;
		}
		timerProduct = setInterval(function(){
			var url = '<%=basePath%>/app?ACTION=viewImportProductDataProgress&USERID=${baihuiId}&SIGN=${sign}&async=true';
			new Ajax.Request(url,{
				onComplete : callback2
			});
		}, 3000);
	}
	
	function callback2(response){
		var ln = response.responseText.evalJSON();
		var err = ln.errMsg;
		var p;
		if(err != null && err < 0){
			clearInterval(timerProduct);
			alert("商品同步异常，请稍后重试!");
			return;
		}
		p = eval(ln.successMsg) / 100;
		if (p>1) p = 1;
		ProgressBar.setProgress(1,p);
		if (p>=1) {clearInterval(timerProduct);	alert("商品同步完成!");}
	}
	
	function importOrderData(){
		ProgressBar.setProgress(2,0);
		var url = '<%=basePath%>/app?ACTION=importOrderData&USERID=${baihuiId}&threeMonthData=0&async=true';
		new Ajax.Request(url,{
			onComplete : callback3
		});
	}
	
	function callback3(response){
		var resText = response.responseText;
		if(resText != null && resText != ""){
			resText = resText.evalJSON();
		}
		var errMsg = resText.errMsg;
		if(errMsg != null){
			alert(errMsg);
			return;
		}
		timerOrder = setInterval(function(){
			var url = '<%=basePath%>/app?ACTION=viewImportOrderDataProgress&USERID=${baihuiId}&SIGN=${sign}&async=true';
			new Ajax.Request(url,{
				onComplete : callback4
			});
		}, 3000);
	}
	
	function callback4(response){
		var ln = response.responseText.evalJSON();
		var err = ln.errMsg;
		var p;
		if(err != null && err < 0){
			clearInterval(timerOrder);
			alert("订单同步异常，请稍后重试!");
			return;
		}
		var p = eval(ln.successMsg) / 100;
		if (p>1) p = 1;
		ProgressBar.setProgress(2,p);
		if (p>=1) {clearInterval(timerOrder);alert("订单同步完成!");}
	}

	
var ProgressBar = {
	width: 315,
	height: 27,
	_progress_1: 0,
	_progress_2: 0,

	init: function(container1, container2){
		container1.innerHTML = "<div style='background:transparent url(<%=basePath%>/jsps/images/linknone.jpg) left top; height:"+ProgressBar.height+"px; width:"+ProgressBar.width+"px'><div id='pbar_1' style='background:transparent url(<%=basePath%>/jsps/images/lineover.jpg) left top; height:"+ProgressBar.height+"px; width:0px'></div>";
		container2.innerHTML = "<div style='background:transparent url(<%=basePath%>/jsps/images/linknone.jpg) left top; height:"+ProgressBar.height+"px; width:"+ProgressBar.width+"px'><div id='pbar_2' style='background:transparent url(<%=basePath%>/jsps/images/lineover.jpg) left top; height:"+ProgressBar.height+"px; width:0px'></div>";
		ProgressBar._progress_1 = 0;
		ProgressBar._progress_2 = 0;
	},

	setProgress: function(n, p){
		document.getElementById("pbar_"+n).style.width = (ProgressBar.width * p)+"px";
		if (n == 1) ProgressBar._progress_1 = p;
		else ProgressBar._progress_2 = p;
	},

	getProgress: function(n){
		if (n == 1) return ProgressBar._progress_1;
		else return ProgressBar._progress_2;
	}
};

ProgressBar.init(document.getElementById("product"), document.getElementById("order"));
</script>
</body>
</html>